package com.rd.sys.common.utils;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.rd.sys.dto.client.store.Material;
import com.rd.sys.dto.client.store.Result;

/**
 * 列表转Select表单工具类.
 */
public class List2SelectUtil {

    /** The Constant ALL. */
    private static final String ALL = "--所有--";

    public static Map<String, String> getValues(List<?> list, boolean isAll) {
        Map<String, String> nameMap = new LinkedHashMap<String, String>();
        if (isAll) {
            nameMap.put("", ALL);
        }
        if (list != null && list.size() > 0) {
            Object obj = null;
            for (int i = 0; i < list.size(); i++) {
                obj = list.get(i);
                if (obj instanceof Result) {
                    nameMap.put(((Result) obj).getResultCode(), ((Result) obj).getResultName());
                } else if (obj instanceof Material) {
                    nameMap.put(((Material) obj).getCode(), ((Material) obj).getName());
                }
            }
        }

        return nameMap;
    }

    public static Map<String, String> getValues(List<?> list) {
        return getValues(list, false);
    }

}
